package com.subframe7536.sa.security.handler;

import org.example.service.base.ResponseResult;
import com.subframe7536.sa.utils.ResponseUtil;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author subframe7536
 */
@Component
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) {
        ResponseResult<String> result = ResponseResult.failed(HttpStatus.FORBIDDEN.value(), "您的权限不足");
        ResponseUtil.renderJson(response, result);
    }

}
